﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CFE;

namespace CFEApp.ViewModels
{
	class MainWindowViewModel
	{

		private Project project;
		private Dictionary<Project.WorkItem, WorkItemViewModel> items;

		public MainWindowViewModel(Project proj)
		{
			project = proj;
			items = new Dictionary<Project.WorkItem, WorkItemViewModel>();
			foreach (var item in project.Items)
			{
				items.Add(item, new WorkItemViewModel(item));
			}
		}

		public string Name { get { return project.Name; } }

		public IEnumerable<WorkItemViewModel> Items
		{
			get
			{
				return items.Values;
			}
		}


		public class WorkItemViewModel
		{
			private Project.WorkItem item;

			public WorkItemViewModel(Project.WorkItem workItem)
			{
				item = workItem;
			}

			public string Name { get { return item.Name; } }
			public string OutputFilename { get { return item.OutputFilename; } }
			public IEnumerable<string> InputFilenames { get { return item.InputFilenames; } }
			public bool BuildOK { get; set; }
			public string LastOutput { get; set; }

			public System.Windows.Media.Color BackgroundColor
			{
				get
				{
					return System.Windows.Media.Colors.Red;
				}
			}
		}





		internal void UpdateWorkItem(ClosureProxy.CompilationCompleteEventArgs e)
		{
			var viewModel = items[e.WorkItem];
			viewModel.BuildOK = e.Success;
			viewModel.LastOutput = e.Output;
		}
	}
}
